<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/pt_BR/sdk.js#xfbml=1&appId=813448282020330&version=v2.0";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
    <style>
      #map-canvas{
          height: 400px;
          width: 100%;
      }
    </style>
<?php if (!is_null($this->message)):?>
<div class="alert alert-success">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        <?php echo Messages::getMessage($this->message);?>
</div>
<?php endif;?>      
<div class="row">
    <div class="col-md-4">
        <h3><i class="glyphicon glyphicon-screenshot"></i> &Aacute;rea Prefer&ecirc;ncia</h3>
        <table class="table table-striped">
        <?php foreach ($this->simulacoes[TipoSimulacao::REGIAO_PREFERIDA] as $nomeLista => $simulacao):?>
            <th colspan="2" style="text-align: center">
            <?php echo $this->href(array('controller' => 'compra', 'action' => 'listar', 'module' => 'default', 'attribs' => array('data-toggle' => 'tooltip', 'data-placement' => 'bottom', 'title' => 'Ver detalhes da lista'), 'content' => "{$nomeLista}", 'checkAcl' => true))?>
            </th>
            
            <?php foreach ($simulacao as $mercado): ?>
            <tr>                
                <td><?php echo $mercado['nome'] ?></td>
                <td width="35%">R$ <?php echo str_replace('.', ',' , $mercado['valor']) ?></td>
            </tr>
            <?php endforeach; ?>
        <?php endforeach; ?>
        </table>
    </div>
    <div class="col-md-4">
        <h3><i class="glyphicon glyphicon-heart"></i> Mercados Preferidos</h3>
        <table class="table table-striped">
        <?php foreach ($this->simulacoes[TipoSimulacao::MERCADO_PREFERIDO] as $nomeLista => $simulacao):?>
            <th colspan="2" style="text-align: center">
            <?php echo $this->href(array('controller' => 'compra', 'action' => 'listar', 'module' => 'default', 'attribs' => array('data-toggle' => 'tooltip', 'data-placement' => 'bottom', 'title' => 'Ver detalhes da lista'), 'content' => "{$nomeLista}", 'checkAcl' => true))?>            
            </th>
            <?php foreach ($simulacao as $mercado): ?>
            <tr>                
                <td><?php echo $mercado['nome'] ?></td>
                <td width="35%">R$ <?php echo str_replace('.', ',' , $mercado['valor']) ?></td>
            </tr>
            <?php endforeach; ?>
        <?php endforeach; ?>
        </table>
    </div>
    <div class="col-md-4">
        <h3><i class="glyphicon glyphicon-map-marker"></i> Geolocaliza&ccedil;&atilde;o</h3>
        <table class="table table-striped">
        <?php foreach ($this->simulacoes[TipoSimulacao::GEOLOCALIZACAO] as $nomeLista => $simulacao):?>
            <th colspan="2" style="text-align: center">
            <?php echo $this->href(array('controller' => 'compra', 'action' => 'listar', 'module' => 'default', 'attribs' => array('data-toggle' => 'tooltip', 'data-placement' => 'bottom', 'title' => 'Ver detalhes da lista'), 'content' => "{$nomeLista}", 'checkAcl' => true))?>            
            </th>
            <?php foreach ($simulacao as $mercado): ?>
            <tr>                
                <td><?php echo $mercado['nome'] ?></td>
                <td width="35%">R$ <?php echo str_replace('.', ',' , $mercado['valor']) ?></td>
            </tr>
            <?php endforeach; ?>
        <?php endforeach; ?>
        </table>
    </div>
</div>
<div class="row">
	<div class="col-md-12" style="text-align:center">
		<?php echo $this->href(array('controller' => 'usuario', 'action' => 'simulacao', 'module' => 'default', 'attribs' => array('data-toggle' => 'tooltip', 'data-placement' => 'rigth', 'title' => 'Ver Simula&ccedil;&otilde;es para outras listas'), 'content' => '<i class="glyphicon glyphicon-eye-open"></i>', 'checkAcl' => true))?>    
	</div>	
	<hr></hr>
</div> 

<div class="row">
	<div class="col-md-4">
            <div id="mapa-index">
		<h2>Mercados</h2>
		<div id="map-canvas"><img src="<?php echo $this->baseUrl() ?>/public/img/ui-anim_basic_16x16.gif" /></div>
                <div class="row">
                    <div class="col-md-6">
                        <?php echo $this->href(array('controller' => 'mercado', 'action' => 'list-in-map', 'module' => 'default', 'attribs' => array('data-toggle' => 'tooltip', 'data-placement' => 'right', 'title' => 'Mapa Ampliado'), 'content' => '<i class="glyphicon glyphicon-fullscreen"></i>', 'checkAcl' => true))?>    
                    </div>
                    <div class="col-md-6" style="text-align: right">
                        <?php echo $this->href(array('controller' => 'mercado', 'action' => 'add-mercado-preferido', 'module' => 'default', 'attribs' => array('data-toggle' => 'tooltip', 'data-placement' => 'left', 'title' => 'Ver em Lista'), 'content' => '<i class="glyphicon glyphicon-list"></i>', 'checkAcl' => true))?>   
                    </div>
                </div>
            </div>
	</div>
        <div class="col-md-4" style="margin-top: 30px">
            <p style="text-align: center"><a href="<?php echo $this->baseUrl()?>/index/livre"><button class="btn btn-primary btn-lg">Buscar Produtos e Pre&ccedil;os</button></a></p>
            <p style="text-align: center"><a href="<?php echo $this->baseUrl()?>/index/livre"><button class="btn btn-primary btn-lg">Reportar Pre&ccedil;os</button></a></p>
	</div>
	<div class="col-md-4">
            <div id="ranking">
		<h2>Pontua&ccedil&atildeo</h2>
                <table class="table table-striped">
                    <?php $i = 1 ?>
                    <?php foreach ($this->usuarios as $usuario) { ?>
                    <tr>
                        <td><?php echo $i++ ?></td>
                        <td><img src="https://graph.facebook.com/<?php echo $usuario->id_user_facebook ?>/picture?width=30&height=30" class="img-circle" width="30" height="30" onerror="this.src='<?php echo $this->baseUrl()?>/public/img/avatar.jpg'"></td>
                        <td>
                        <?php if ($usuario->id_user_facebook != ''):?>
                        <a href="https://www.facebook.com/<?php echo $usuario->id_user_facebook ?>"><?php echo strtoupper($this->apelido($usuario->nm_pessoa)) ?></a>
                        <?php else:?>
                        <?php echo strtoupper($this->apelido($usuario->nm_pessoa)) ?>
                        <?php endif;?>
                        </td>
                        <td><?php echo $usuario->getPontuacao() . ' pts.' ?></td>
                    </tr>
                    <?php if ($i == 10) break; ?>
                    <?php } ?>
                </table>
            </div>
	</div>
</div>

<div class="row">
	<div class="fb-comments" data-href="https://www.facebook.com/pages/Mercado-Legal/1476312665968581?fref=ts" data-numposts="5" data-colorscheme="light"></div>
</div>
<div class="baseUrl"><?php echo $this->baseUrl() ?></div>




<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script type="text/javascript" src="<?php echo $this->baseUrl() ?>/public/js/jquery.js"></script>
<script type="text/javascript" src="<?php echo $this->baseUrl() ?>/public/js/maps-mercados-coordenada.js"></script>
<script type="text/javascript" src="<?php echo $this->baseUrl() ?>/public/js/gps.js"></script>